package vy.org.app.common;

import java.util.HashMap;
import java.util.Map;

public class BaseEnum {
	private static Map<Class<? extends BaseEnum>, Map<Object,BaseEnum>> enumMap = null;
	private Integer id;
	private String name;

	static {
		//Empty block to initialize
		enumMap = new HashMap<Class<? extends BaseEnum>, Map<Object, BaseEnum>>();
	}
	
	public BaseEnum(Integer id){
		this(id,null);
	}
	
	public BaseEnum(Integer id, String name){
		Map<Object, BaseEnum> enumValMap = null;
		
		if(enumMap.containsKey(this.getClass())){
			enumValMap = enumMap.get(this.getClass());
		}else{
			enumValMap = new HashMap<Object, BaseEnum>();
			enumMap.put(this.getClass(), enumValMap);
		}
		enumValMap.put(id, this);
		this.id = id;
		this.name = name;
	}
	
	public Integer getId() {
		return id;
	}
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}

	public static final BaseEnum get(Integer key, Class<? extends BaseEnum> cls){
		Map<Object, BaseEnum> enumValMap = enumMap.get(cls);
		if(enumValMap != null)
			return enumValMap.get(key);
		else
			return null;
	}
	
	public static final Map<Object, BaseEnum> get(Class<? extends BaseEnum> cls){
		return (Map<Object, BaseEnum>)enumMap.get(cls);
	}
	
	public static void init(Class<? extends BaseEnum> cls) {
		
	}
}
